import com.wzy.MyFactory;
import com.wzy.MyRunable;

public class MyFactoryTest {

    public static void main(String[] args) {

        //在多线程的情况下，懒汉模式会出现线程安全问题
        MyRunable mr = new MyRunable();

        Thread cx = new Thread(mr);
        cx.setName("查询");

        Thread xz = new Thread(mr);
        xz.setName("新增");

        cx.start();
        xz.start();

        System.out.println(Thread.currentThread().getName());
        //多次调用MyFactory.getInstance();只会创建一个factory实例
        MyFactory factory = MyFactory.getInstance();
        factory = MyFactory.getInstance();
        factory = MyFactory.getInstance();
        factory = MyFactory.getInstance();
    }
}
